package services

import (
	"errors"
	"fmt"
	"gowww/comeon/comonpents/taobao"
	"gowww/comeon/comonpents/topsdk"
	"gowww/comeon/comonpents/topsdk/ability2138"
	request2 "gowww/comeon/comonpents/topsdk/ability2138/request"
	"gowww/comeon/comonpents/topsdk/ability375"
	"gowww/comeon/comonpents/topsdk/ability375/request"
)

type Taobao struct{}

//
//  GetTbPasswd
//  @Description: 获取淘口令
//  @receiver tb
//  @param urlParam
//  @return error
//
func (tb *Taobao) GetTbPasswd(urlParam string) (data interface{}, error error) {

	if urlParam == "" {
		return nil, errors.New("缺少参数")
	}
	//taobao.GetTaoPasswd(data)
	topClient := topsdk.NewDefaultTopClient(taobao.AppKey, taobao.AppSecret, taobao.API, 20000, 20000)
	ability := ability375.NewAbility375(&topClient)

	var req request.TaobaoTbkTpwdCreateRequest
	req.SetUrl(urlParam)
	resp, err := ability.TaobaoTbkTpwdCreate(&req)
	if err != nil {
		return nil, err
	}

	data = map[string]string{
		"passwordSimple": *resp.Data.PasswordSimple,
		"model":          *resp.Data.Model,
	}
	return data, nil
}

//
//  GetOrder
//  @Description:
//  @receiver tb
//  @return data
//  @return err
//
func (tb *Taobao) GetOrder() (data interface{}, err error) {

	client := topsdk.NewDefaultTopClient(taobao.AppKey, taobao.AppSecret, taobao.API, 20000, 20000)

	ability := ability2138.NewAbility2138(&client)

	var req request2.TaobaoTbkDgNewuserOrderGetRequest
	//req.SetStartTime(util.LocalTime(time.Now()))
	req.SetPageSize(20)
	req.SetPageNo(1)

	resp, err := ability.TaobaoTbkDgNewuserOrderGet(&req)
	if err != nil {
		return nil, err
	}

	data = map[string]string{}
	fmt.Println(resp)
	return data, nil
}
